package com.prs.crm.dao.cdxh.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cdxh.HrPersonDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cdxh.HrPerson;
import com.prs.crm.domain.cdxh.production.MachineClass;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-6 上午11:59:04
 * 简单说明
 */

public class HrPersonDaoImpl extends BaseDaoImpl<HrPerson> implements
		HrPersonDao {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public HrPerson getHrPersonDao(final String name,final String department) {
		return (HrPerson)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(HrPerson.class);
				        	criteria.add(Restrictions.eq("hrDepartment", department));
				        	criteria.add(Restrictions.eq("hrName", name));			        	
				        	List<HrPerson> result = criteria.list();
				        	int zsize=result.size();
				        		if(zsize==0){
				        			return null;
				        		}else{
				        			return result.get(0);
				        		}
				         
				 } });
	}

	@Override
	public void saveOrHrPersonDao(HrPerson hrPerson) {
		this.getHibernateTemplate().saveOrUpdate(hrPerson);
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public HrPerson getHrPersonMoney(final String name,final String department,
			final String recordMonth) {
		return (HrPerson)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(HrPerson.class);
				        	criteria.add(Restrictions.eq("hrDepartment", department));
				        	criteria.add(Restrictions.eq("hrName", name));	
				        	criteria.add(Restrictions.eq("recordMonth", recordMonth));
				        	List<HrPerson> result = criteria.list();
				        	int zsize=result.size();
				        		if(zsize==0){
				        			return null;
				        		}else{
				        			return result.get(0);
				        		}
				         
				 } });
	}

}
